package com.juli.aimanager.base.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Service;

import com.juli.aimanager.base.service.BaseService;
import com.juli.aimanager.dao.BaseDao;
import com.juli.aimanager.util.TableGrid;
import com.juli.aimanager.util.TableGridJson;
@Service
public class BaseServiceImpl implements BaseService {
	
	@Resource(name="baseDao")
	public BaseDao baseDao;

	public List getChartLegend(Map<String, String> map) throws Exception {
		String sql="select * from col_config_page where 1=1 and ischart=1 [ and pageid={function_id} ]";
		return baseDao.findAll(sql, map);
	}

	public List getChartSelectedLegend(Map<String, String> map)
			throws Exception {
		String sql="select * from col_config_page where 1=1 and ischart=1 CHART_SELECTED='1'  [ and pageid={function_id} ]";
		return baseDao.findAll(sql, map);
	}
	
	public String getTableGrid(Map<String, String> map) throws Exception {
		
		return this.getTableGrid(map,"1");
	}

	public String getTableGrid(Map<String, String> map, String tabIndex)
			throws Exception {
		// TODO Auto-generated method stub
		String sql="select  fieldname field , lower(ishiddle) hidden,caption title, '' align, 'true' sortable, " +
				" renderer formatter, 'true' resizable,width , isprimary checkbox  from col_config_page where 1=1  [ and pageid={function_id} ]  ";
		if(tabIndex!=null&&!"".equals(tabIndex)){
			sql+=" and tabindex="+tabIndex;
		}
		sql+=" order by orderid ";
		List list=baseDao.findAllObject(sql,map,TableGrid.class);
		
		String json="[[";
		for(int i=0;i<list.size();i++){
			TableGrid tableGird=(TableGrid)list.get(i);
			json+=TableGridJson.getTableGridJson(tableGird)+" ";
			if(i<list.size()-1){
				json+=",";
			}
		
		}
		json+="]]";
		return json.toString();
	}
	
	

}
